<template>
	<view class="feedback-container">
		<!-- 反馈分类 -->
		<view class="section-title">反馈分类</view>
		<view class="category-list">
			<view 
				v-for="(item, index) in categories" 
				:key="index" 
				class="category-item" 
				:class="{ active: selectedCategory === index }"
				@click="selectCategory(index)"
			>
				分类{{ index + 1 }}
			</view>
		</view>
		
		<!-- 反馈问题 -->
		<view class="section-title">反馈问题</view>
		<view class="feedback-content">
			<textarea 
				class="feedback-textarea" 
				v-model="feedbackContent" 
				placeholder="请输入您的反馈内容" 
				maxlength="500"
			></textarea>
			<view class="word-count">{{ feedbackContent.length }}/500</view>
		</view>
		
		<!-- 问题图片 -->
		<view class="section-title">问题图片</view>
		<view class="image-upload">
			<view class="upload-box" @click="chooseImage">
				<text class="upload-icon">+</text>
			</view>
			<view class="image-preview" v-for="(item, index) in imageList" :key="index">
				<image :src="item" mode="aspectFill"></image>
				<view class="delete-icon" @click="deleteImage(index)">×</view>
			</view>
		</view>
		
		<!-- 联系姓名 -->
		<view class="section-title">联系姓名</view>
		<view class="input-box">
			<input 
				type="text" 
				v-model="contactName" 
				placeholder="请输入姓名" 
				placeholder-class="placeholder"
			/>
		</view>
		
		<!-- 联系电话 -->
		<view class="section-title">联系电话</view>
		<view class="input-box">
			<input 
				type="number" 
				v-model="contactPhone" 
				placeholder="请输入电话" 
				placeholder-class="placeholder"
			/>
		</view>
		
		<!-- 提交按钮 -->
		<view class="submit-btn" @click="submitFeedback">提交</view>
		<view class="submit-tips">提交反馈</view>
	</view>
</template>

<script>
/**
 * 反馈页面
 * @description 用户提交反馈问题的页面
 */
export default {
	data() {
		return {
			/**
			 * 反馈分类列表
			 * @type {Array}
			 */
			categories: [1, 2, 3, 4, 5, 6],
			
			/**
			 * 当前选中的分类索引
			 * @type {Number}
			 */
			selectedCategory: 0,
			
			/**
			 * 反馈内容
			 * @type {String}
			 */
			feedbackContent: '',
			
			/**
			 * 上传的图片列表
			 * @type {Array}
			 */
			imageList: [],
			
			/**
			 * 联系人姓名
			 * @type {String}
			 */
			contactName: '',
			
			/**
			 * 联系人电话
			 * @type {String}
			 */
			contactPhone: ''
		};
	},
	methods: {
		/**
		 * 选择反馈分类
		 * @param {Number} index - 分类索引
		 */
		selectCategory(index) {
			this.selectedCategory = index;
		},
		
		/**
		 * 选择图片
		 */
		chooseImage() {
			if (this.imageList.length >= 9) {
				uni.showToast({
					title: '最多上传9张图片',
					icon: 'none'
				});
				return;
			}
			
			uni.chooseImage({
				count: 9 - this.imageList.length,
				sizeType: ['compressed'],
				sourceType: ['album', 'camera'],
				success: (res) => {
					this.imageList = [...this.imageList, ...res.tempFilePaths];
				}
			});
		},
		
		/**
		 * 删除图片
		 * @param {Number} index - 图片索引
		 */
		deleteImage(index) {
			this.imageList.splice(index, 1);
		},
		
		/**
		 * 提交反馈
		 */
		submitFeedback() {
			// 表单验证
			if (!this.feedbackContent.trim()) {
				uni.showToast({
					title: '请输入反馈内容',
					icon: 'none'
				});
				return;
			}
			
			if (!this.contactName.trim()) {
				uni.showToast({
					title: '请输入联系人姓名',
					icon: 'none'
				});
				return;
			}
			
			if (!this.contactPhone.trim()) {
				uni.showToast({
					title: '请输入联系电话',
					icon: 'none'
				});
				return;
			}
			
			// 手机号验证
			const phoneReg = /^1[3-9]\d{9}$/;
			if (!phoneReg.test(this.contactPhone)) {
				uni.showToast({
					title: '请输入正确的手机号',
					icon: 'none'
				});
				return;
			}
			
			// 显示加载中
			uni.showLoading({
				title: '提交中...'
			});
			
			// 模拟提交
			setTimeout(() => {
				uni.hideLoading();
				uni.showToast({
					title: '提交成功',
					icon: 'success',
					duration: 2000,
					success: () => {
						// 延迟返回上一页
						setTimeout(() => {
							uni.navigateBack();
						}, 2000);
					}
				});
			}, 1500);
		}
	}
}
</script>

<style lang="scss" scoped>
.feedback-container {
	padding: 30rpx;
	background-color: #fff;
	min-height: 100vh;
	
	// 标题样式
	.section-title {
		font-size: 30rpx;
		font-weight: bold;
		color: #333;
		margin-bottom: 20rpx;
		margin-top: 30rpx;
		
		&:first-child {
			margin-top: 0;
		}
	}
	
	// 分类列表
	.category-list {
		display: flex;
		flex-wrap: wrap;
		gap: 20rpx;
		justify-content: space-between;
		.category-item {
			padding: 18rpx 0;
			width: 30%;
			text-align: center;
			background-color: #f0f0f0;
			border-radius: 50rpx;
			font-size: 28rpx;
			color: #666;
			
			&.active {
				background-color: #529AEE;
				color: #fff;
			}
		}
	}
	
	// 反馈内容区域
	.feedback-content {
		position: relative;
		background-color: #f0f0f0;
		border-radius: 20rpx;
		padding: 20rpx;
		
		.feedback-textarea {
			width: 100%;
			height: 300rpx;
			font-size: 28rpx;
			line-height: 1.5;
			color: #333;
		}
		
		.word-count {
			position: absolute;
			right: 20rpx;
			bottom: 20rpx;
			font-size: 24rpx;
			color: #999;
		}
	}
	
	// 图片上传区域
	.image-upload {
		display: flex;
		flex-wrap: wrap;
		gap: 20rpx;
		
		.upload-box {
			width: 160rpx;
			height: 160rpx;
			background-color: #f0f0f0;
			border-radius: 10rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			
			.upload-icon {
				font-size: 80rpx;
				color: #ccc;
				line-height: 1;
			}
		}
		
		.image-preview {
			width: 160rpx;
			height: 160rpx;
			position: relative;
			
			image {
				width: 100%;
				height: 100%;
				border-radius: 10rpx;
			}
			
			.delete-icon {
				position: absolute;
				top: -20rpx;
				right: -20rpx;
				width: 40rpx;
				height: 40rpx;
				background-color: rgba(0, 0, 0, 0.5);
				color: #fff;
				border-radius: 50%;
				display: flex;
				justify-content: center;
				align-items: center;
				font-size: 30rpx;
			}
		}
	}
	
	// 输入框样式
	.input-box {
		background-color: #f0f0f0;
		border-radius: 20rpx;
		padding: 20rpx;
		
		input {
			width: 100%;
			height: 60rpx;
			font-size: 28rpx;
			color: #333;
		}
		
		.placeholder {
			color: #999;
		}
	}
	
	// 提交按钮
	.submit-btn {
		margin-top: 60rpx;
		background-color: #529AEE;
		color: #fff;
		font-size: 32rpx;
		font-weight: bold;
		height: 90rpx;
		line-height: 90rpx;
		text-align: center;
		border-radius: 45rpx;
	}
	.submit-tips{
		margin-top: 30rpx;
		font-size: 28rpx;
		color: #529AEE;
		text-align: center;
	}
}
</style>
